package com.juitar.base.enumerator;

import java.util.ArrayList;

import com.juitar.base.Chord;
import com.juitar.base.Tuning;

public class ArrayFretEnumeratorFactory implements IFingeringEnumeratorFactory {

    public FingeringEnumerator create(Chord chord, Tuning tuning) {
        int[] open = tuning.getOpenStringNotes();
        IFretEnumerator[] fretEnums = new IFretEnumerator[open.length];
        for (int i = 0; i < open.length; i++) {
            ArrayList<Integer> list = new ArrayList<Integer>();
            list.add(new Integer(-1)); // muted string
            for (int j = 0; j < 12; j++) {
                int current = open[i] + j;
                int contains = chord.contains(current);
                if (contains > 0) {
                    list.add(new Integer(j));
                }
            }
            fretEnums[i] = new ArrayFretEnumerator(list.toArray());
        }
        return new FingeringEnumerator(fretEnums);
    }
}
